package com.qf.rbac2202.shiro;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;

import java.util.HashMap;
import java.util.Properties;

@Configuration
public class FreeMarkerConfig {

    @Bean
    public FreeMarkerConfigurer freeMarkerConfigurer(ShiroTag shiroTag){

        final FreeMarkerConfigurer freeMarkerConfig = new FreeMarkerConfigurer();

        // 1. 配置freemarker 模板的路径
        freeMarkerConfig.setTemplateLoaderPath("classpath:/templates");

        // 2. 配置 freemarker解析解析  shiroTag
        // 即 <#if shiro.hasPermission("sys:user:save")>

        final HashMap<String, Object> map = new HashMap<>();

        map.put("shiro",shiroTag);

        freeMarkerConfig.setFreemarkerVariables(map);


        // 3. 配置 freemarker 使用的字符编码
        final Properties properties = new Properties();

        properties.setProperty("default_encoding","utf-8");
        properties.setProperty("number_format","0.##");

        freeMarkerConfig.setFreemarkerSettings(properties);

        return freeMarkerConfig;

    }

}
